<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
    <th:block th:include="include :: header('文章列表')" />
    <th:block th:include="include :: select2-css" />
</head>

<body class="gray-bg">
    <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
                <form id="article-form">
					<div class="select-list">
						<ul>
							<li>文章标题：<input class="form-control" type="text" placeholder="文章标题" name="articleTitle" />

							</li>
                            <li>
                                分类ID：<input class="form-control" type="number" name="catId" th:value="${catId}" />
                            </li>
							<li>文章ID：<input class="form-control" type="number" placeholder="文章ID" name="articleId" />
							</li>
							<li>创建人ID：<input class="form-control" type="number" placeholder="创建人ID" name="createBy" />
							</li>
							<li>文章状态：<select class="form-control" name="visible"
									th:with="type=${@dictTag.getType('cms_article_visible')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
										th:value="${dict.dictValue}">
								</select>
							</li>
							<li>文章顶置：<select class="form-control" name="articleTop"
									th:with="type=${@dictTag.getType('cms_article_top')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
										th:value="${dict.dictValue}">
								</select>
							</li>
							<li>文章类型：<select class="form-control" name="articleType"
									th:with="type=${@dictTag.getType('cms_article_type')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
										th:value="${dict.dictValue}">
								</select>
							</li>
							<li>文章所属：<select class="form-control" name="params[supportTheme]">
									<option value="">所有</option>
									<option th:each="themeName: ${themeNames}" th:text="${themeName}"
										th:value="${themeName}">
								</select>
							</li>
							<li class="select-time"><label>创建时间： </label> <input type="text" class="time-input"
									id="startTime" placeholder="开始时间" name="params[beginTime]" /> <span>-</span> <input
									type="text" class="time-input" id="endTime" placeholder="结束时间"
									name="params[endTime]" /></li>
							<li><a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
										class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="reloadForm()"><i
										class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <div class="btn-group" shiro:hasPermission="cms:article:edit">
                    <button class="btn btn-primary multiple disabled" onclick="removrRelation()"> 解除关联
                    </button>
                </div>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <div th:include="include :: footer"></div>
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "cms/article";
        var articleTypes = [[${@dictTag.getType('cms_article_type') }]], articleTops = [[${@dictTag.getType('cms_article_top') }]], articleVisibles = [[${@dictTag.getType('cms_article_visible') }]];
        $(function () {
            var options = {
                url: prefix + "/list",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "文章列表",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'articleId',
                    title: '文章id'
                },
                {
                    field: 'articleTitle',
                    title: '文章标题',
                    formatter: function (value, row, index) {
                        if (value.length > 12) {
                            return '<a href="#" title="' + value + '">' + value.substring(0, 12) + '..</a>';
                        }
                        else {
                            return '<a href="#" title="' + value + '">' + value + '</a>';
                        }
                    }
                },
                {
                    field: 'articleTop',
                    title: '顶置级别',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(articleTops, value);
                    }
                },
                {

                    field: 'visible',
                    title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(articleVisibles, value);
                    }
                },
                {
                    field: 'keywords',
                    title: '关键词',
                    align: "left",
                    visible: false
                },
                {
                    field: 'description',
                    title: '描述',
                    align: "left",
                    visible: false
                },
                {

                    title: '是否允许评论',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.allowComment == 1) {
                            return '<i class=\"fa fa-toggle-on text-info fa-2x\" "></i> ';
                        } else {

                            return '<i class=\"fa fa-toggle-off text-info fa-2x\" "></i> ';
                        }
                    }
                },
                {
                    field: 'articleType',
                    title: '文章类型',
                    formatter: function (value, item, index) {

                        return $.table.selectDictLabel(articleTypes, value);

                    }
                },
                {
                    field: 'createBy',
                    title: '创建人Id'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                }]
            };
            $.table.init(options);
        });

        function removrRelation() {
            //获取选中行数据
            var pam = {}, articleIds = [], chooseData = $("#bootstrap-table").bootstrapTable('getSelections');
            pam.catId = $("input[name='catId']").val();
            if (chooseData.length > 0) {
                $.each(chooseData, function (index, ele) {
                    articleIds.push(ele.articleId);
                });
                pam.articleIds = articleIds.join();
                $.modal.confirm("确定要解除关联吗？", function () {
                    $.operate.post(prefix + "/removeCatArticles", pam);
                })
            }
            else {
                $.modal.alert("请至少选择一项");
            }

        }

        /* 添加用户-选择用户-提交 */
        function submitHandler() {
            $.modal.close();
			// 父页面的方法
			// parent.selectUsers();
			// 父页面的变量
			parent.$.table.search();
        }
    </script>
</body>

</html>